package com.hiwhitley.easy.day10;

import static java.lang.Math.log;
import static java.lang.Math.log10;

/**
 * Created by hiwhitley on 2016/8/14.
 */
public class IsPowerOfThree {
    public boolean isPowerOfThree(int n) {
        if (n == 1) return true;
        else if (n == 0) return false;
        else if (n % 3 == 0)
            return isPowerOfThree(n / 3);
        else return false;
    }

    public boolean isPowerOfThree2(int n) {
        return (n > 0 && 1162261467 % n == 0);
    }

    public boolean isPowerOfThree3(int n) {
        return (n > 0 && ((int) (Math.log10(n) / Math.log10(3))) - Math.log10(n) / Math.log10(3) == 0);
    }
}
